package com.woorigil.social.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import org.apache.commons.lang.StringUtils;

/**
 * 문자열의 길이가 초과 하면 말줄임표를 붙인다.
 */
public class StringReduceTag extends SimpleTagSupport {
	private String text;
	private int length;
	
	@Override
	public void doTag() throws JspException, IOException {
		if (StringUtils.isBlank(text)) {
			return;
		}
		
		String output = text;
		int textLength = StringUtils.trimToEmpty(text).length();
		
		if (textLength > length) {
			output = text.substring(0, length) + "..";
		}
		getJspContext().getOut().write(output);
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}
}